package com.yuliang.proxy;

import com.yuliang.UserService;
import com.yuliang.UserServiceImpl;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;


public class MyJDKProxy {



    public static void main(String[] args) {
        UserService userService = new UserServiceImpl();


        InvocationHandler invocationHandler = new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println("======= i am before =======");
                Object invoke = method.invoke(userService, args);

                return invoke;
            }
        };

        Proxy.newProxyInstance(MyJDKProxy.class.getClassLoader(),UserService.class.getInterfaces(),invocationHandler);

        userService.register();
        userService.login("sa","11");
    }
}
